﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using jnxc.Model;
namespace jnxc.BLL
{
	/// <summary>
	/// userinfo
	/// </summary>
	public partial class userinfo
	{
		private readonly jnxc.DAL.userinfo dal=new jnxc.DAL.userinfo();
		public userinfo()
		{}
		#region  BasicMethod
        public DataSet Login(string name, string pwd)
        {
            return dal.Login(name, pwd);
        }
        public jnxc.Model.userinfo Login(string name, string pwd, int i)
        {
            return dal.Login(name, pwd, 1);
        }
        /// <summary>
        /// 通过用户名直接登录
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public DataSet LoginData(int id) 
        {
            return dal.LoginData(id);
        }
        /// <summary>
        /// 通过用户名直接登录
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public jnxc.Model.userinfo Login(int uid)
        {
            return dal.Login(uid);
        }
        public bool Updatea(jnxc.Model.userinfo model)
        {
            return dal.Updatea(model);
        }
        public bool Updatepass(int uid, string oldpass, string newpass)
        {
            return dal.Updatepass(uid, oldpass, newpass);
        }
        public bool Updatemyinfo(jnxc.Model.userinfo model)
        {
            return dal.Updatemyinfo(model);
        }
		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int uid)
		{
			return dal.Exists(uid);
		}
        public bool Exists(string uname)
        {
            return dal.Exists(uname);
        }

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(jnxc.Model.userinfo model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(jnxc.Model.userinfo model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int uid)
		{
            
			return dal.Delete(uid);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string uidlist )
		{
            return dal.DeleteList(Maticsoft.Common.PageValidate.SafeLongFilter(uidlist, 0));
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public jnxc.Model.userinfo GetModel(int uid)
		{
			
			return dal.GetModel(uid);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public jnxc.Model.userinfo GetModelByCache(int uid)
		{
			
			string CacheKey = "userinfoModel-" + uid;
			object objModel = jnxc.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(uid);
					if (objModel != null)
					{
						int ModelCache = jnxc.Common.ConfigHelper.GetConfigInt("ModelCache");
						jnxc.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (jnxc.Model.userinfo)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<jnxc.Model.userinfo> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<jnxc.Model.userinfo> DataTableToList(DataTable dt)
		{
			List<jnxc.Model.userinfo> modelList = new List<jnxc.Model.userinfo>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				jnxc.Model.userinfo model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
					}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
        public int GetRecordCountm(string strWhere)
        {
            return dal.GetRecordCountm(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPagem(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPagem(strWhere, orderby, startIndex, endIndex);
        }
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod
        public string GetZu(int id)
        {
            return dal.GetZu(id);
        }
		#endregion  ExtensionMethod
	}
}

